package sparksql_fenxi

import org.apache.spark.sql.SparkSession

object table_perparation {
  def main(args: Array[String]): Unit = {
    val  spark=SparkSession.builder()
      .appName("test")
      .master("local[*]")
      .enableHiveSupport()
      .getOrCreate()

    spark.sql("use test")

    spark.sql(
      """
        |create table if not exists  course(
        |c_id String,
        |c_name String,
        |t_id String
        |)
        |""".stripMargin)

    spark.sql(
      """
        |insert into course(c_id,c_name,t_id)
        |values
        |('01','语文','02'),
        |('02','数学','01'),
        |('03','英语','03')
        |
        |""".stripMargin)

    println("course表创建完毕，数据准备完毕")


    spark.sql(
      """
        |create table student(
        |s_id String,
        |s_name String,
        |s_birth String,
        |s_sex string
        |)
        |""".stripMargin)

    spark.sql(
      """
        |insert into student(s_id,s_name,s_birth,s_sex)
        |values
        |('01','赵雷','1990-01-01','男'),
        |('02','钱电','1990-12-21','男'),
        |('03','孙风','1990-05-20','男'),
        |('04','李云','1990-08-06','男'),
        |('05','周梅','1991-12-01','女'),
        |('06','吴兰','1992-03-01','女'),
        |('07','郑竹','1989-07-01','女'),
        |('08','王菊','1990-01-20','女')
        |
        |""".stripMargin)

    println("student表创建完毕，数据准备完毕")


    spark.sql(
      """
        |create table score(
        |s_id String,
        |c_id string,
        |s_score int
        |)
        |""".stripMargin)

    spark.sql(
      """
        |insert into score(s_id,c_id,s_score)
        |values
        |('01','01',80),
        |('01','02',90),
        |('01','03',99),
        |('02','01',70),
        |('02','02',60),
        |('02','03',80),
        |('03','01',80),
        |('03','02',80),
        |('03','03',80),
        |('04','01',50),
        |('04','02',30),
        |('04','03',20),
        |('05','01',76),
        |('05','02',87),
        |('06','01',31),
        |('06','03',34),
        |('07','02',89),
        |('07','03',98)
        |
        |""".stripMargin)

    println("score表创建完毕，数据准备完毕")


    spark.sql(
      """
        |create table teacher(
        |t_id string,
        |t_name string
        |)
        |""".stripMargin)

    spark.sql(
      """
        |insert into teacher(t_id,t_name)
        |values
        |('01','张三'),
        |('02','李四'),
        |('03','王五')
        |
        |""".stripMargin)

    println("teacher表创建完毕，数据准备完毕")








    spark.close()
  }

}
